var $ = exports
var _ = require("rosa/html4")

var stdTemplate = require("app/template").standard
var log = java.util.logging.Logger.getLogger("app")

$.setup = function( sandro ) {
	
	require("app/evalControl").setup(sandro, "/eval")
	
	sandro.unsafeRoute("GET", "/unsafe", function(request, response) {
		response.writer.println("Request dispatched by sandro")
	})
	
	sandro.modRoute("GET", "/mod", {	
		"arrayUtils":"objectUtils",
		"rosa/html4":["arrayUtils","objectUtils","rosa/html4Tags"],
		"rosa/template": ["arrayUtils","objectUtils"],
		"app/client/tests": [
		  "test", {	
		  	"test/arrayUtils":["assert","arrayUtils"],
		  	"test/assert":"assert",
		  	"test/require":[
		  	  "assert",
		  	  {"test/require/foo":"test/require/bar"}
		  	],
		  	"test/json":["assert","json"],
		  	"test/rosa/html4":[
		  	  "assert",
		  	  "rosa/html4"
		  	],
		  	"test/rosa/html4Render":[
		  	  {"rosa/html4Render": ["html4Tags", "arrayUtils"]}, 
		  	  "rosa/html4", 
		  	  "assert"
		  	],
		  	"test/rosa/template":[
		  		{"rosa/template": "regexpUtils"},
		  		"rosa/html4Render",
		  		"rosa/html4",
		  		"assert"
		  	]
	    }		    
		]
	})
	
	sandro.htmlRoute("GET", "/", function(){
		var test = require("test")
		var console = require("stringConsole").build()

		test.showInConsole( test.run({ 
			testAssert: require("test/assert"),
			testJson: require("test/json"),
			testRosa: require("test/rosa"),
			testRequire: require("test/require"),
			testSandro: require("test/sandro"),
			testArrayUtils: require("test/arrayUtils"),
			testTengo: require("test/tengo")
		}), console)
		
		return stdTemplate(
	  	_.div({"class":"title"}, "Server side tests"),
	  	_.pre("" + console),
	  	_.div({"class":"title"}, "Client side tests"),
	  	_.pre({id:"clientResults"}, "\n"),
	  	_.fetchMods("/mod", "app/client/tests"),
	  	_.script('require("app/client/tests").run()')
		)
	})
}